{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e3e7afed",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import sqlite3\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "dcd67301",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "本接口即将停止更新，请尽快使用Pro版接口：https://tushare.pro/document/2\n"
     ]
    }
   ],
   "source": [
    "\n",
    "pf=ts.get_hist_data('600848')\n",
    "\n",
    "con=sqlite3.connect('C:\\\\Users\\\\zhang\\\\.vntrader\\\\database.db')#如果路径里面没有这个数据库，会自动创建\n",
    "\n",
    "c=con.cursor()\n",
    "\n",
    "\n",
    "\n",
    "sql=\"select * from DbBarData\"\n",
    "\n",
    "test=pd.read_sql(sql,con)#完成数据库的查询读取到数据框dataframe 中\n",
    "\n",
    " #dataframe 写入mysql\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "85947fcd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>symbol</th>\n",
       "      <th>exchange</th>\n",
       "      <th>datetime</th>\n",
       "      <th>interval</th>\n",
       "      <th>volume</th>\n",
       "      <th>open_interest</th>\n",
       "      <th>open_price</th>\n",
       "      <th>high_price</th>\n",
       "      <th>low_price</th>\n",
       "      <th>close_price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>40921</td>\n",
       "      <td>i2109</td>\n",
       "      <td>DCE</td>\n",
       "      <td>2021-01-28 21:00:00</td>\n",
       "      <td>1m</td>\n",
       "      <td>402.0</td>\n",
       "      <td>107487.0</td>\n",
       "      <td>909.0</td>\n",
       "      <td>912.5</td>\n",
       "      <td>907.5</td>\n",
       "      <td>911.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>40922</td>\n",
       "      <td>i2109</td>\n",
       "      <td>DCE</td>\n",
       "      <td>2021-01-28 21:01:00</td>\n",
       "      <td>1m</td>\n",
       "      <td>204.0</td>\n",
       "      <td>107406.0</td>\n",
       "      <td>912.0</td>\n",
       "      <td>912.0</td>\n",
       "      <td>910.5</td>\n",
       "      <td>910.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>40923</td>\n",
       "      <td>i2109</td>\n",
       "      <td>DCE</td>\n",
       "      <td>2021-01-28 21:02:00</td>\n",
       "      <td>1m</td>\n",
       "      <td>454.0</td>\n",
       "      <td>107210.0</td>\n",
       "      <td>910.0</td>\n",
       "      <td>911.0</td>\n",
       "      <td>906.5</td>\n",
       "      <td>907.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>40924</td>\n",
       "      <td>i2109</td>\n",
       "      <td>DCE</td>\n",
       "      <td>2021-01-28 21:03:00</td>\n",
       "      <td>1m</td>\n",
       "      <td>346.0</td>\n",
       "      <td>107113.0</td>\n",
       "      <td>907.0</td>\n",
       "      <td>910.0</td>\n",
       "      <td>906.0</td>\n",
       "      <td>906.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>40925</td>\n",
       "      <td>i2109</td>\n",
       "      <td>DCE</td>\n",
       "      <td>2021-01-28 21:04:00</td>\n",
       "      <td>1m</td>\n",
       "      <td>231.0</td>\n",
       "      <td>107043.0</td>\n",
       "      <td>905.5</td>\n",
       "      <td>908.5</td>\n",
       "      <td>905.0</td>\n",
       "      <td>907.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>221953</th>\n",
       "      <td>275307</td>\n",
       "      <td>IF2201</td>\n",
       "      <td>CFFEX</td>\n",
       "      <td>2021-12-30 15:24:00</td>\n",
       "      <td>1m</td>\n",
       "      <td>0.0</td>\n",
       "      <td>80206.0</td>\n",
       "      <td>4940.0</td>\n",
       "      <td>4940.0</td>\n",
       "      <td>4940.0</td>\n",
       "      <td>4940.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>221954</th>\n",
       "      <td>275308</td>\n",
       "      <td>IH2201</td>\n",
       "      <td>CFFEX</td>\n",
       "      <td>2021-12-30 15:24:00</td>\n",
       "      <td>1m</td>\n",
       "      <td>0.0</td>\n",
       "      <td>52452.0</td>\n",
       "      <td>3277.0</td>\n",
       "      <td>3277.0</td>\n",
       "      <td>3277.0</td>\n",
       "      <td>3277.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>221955</th>\n",
       "      <td>275309</td>\n",
       "      <td>IC2201</td>\n",
       "      <td>CFFEX</td>\n",
       "      <td>2021-12-30 15:26:00</td>\n",
       "      <td>1m</td>\n",
       "      <td>0.0</td>\n",
       "      <td>94072.0</td>\n",
       "      <td>7342.8</td>\n",
       "      <td>7342.8</td>\n",
       "      <td>7342.8</td>\n",
       "      <td>7342.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>221956</th>\n",
       "      <td>275310</td>\n",
       "      <td>IF2201</td>\n",
       "      <td>CFFEX</td>\n",
       "      <td>2021-12-30 15:26:00</td>\n",
       "      <td>1m</td>\n",
       "      <td>0.0</td>\n",
       "      <td>80206.0</td>\n",
       "      <td>4940.0</td>\n",
       "      <td>4940.0</td>\n",
       "      <td>4940.0</td>\n",
       "      <td>4940.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>221957</th>\n",
       "      <td>275311</td>\n",
       "      <td>IH2201</td>\n",
       "      <td>CFFEX</td>\n",
       "      <td>2021-12-30 15:26:00</td>\n",
       "      <td>1m</td>\n",
       "      <td>0.0</td>\n",
       "      <td>52452.0</td>\n",
       "      <td>3277.0</td>\n",
       "      <td>3277.0</td>\n",
       "      <td>3277.0</td>\n",
       "      <td>3277.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>221958 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            id  symbol exchange             datetime interval  volume  \\\n",
       "0        40921   i2109      DCE  2021-01-28 21:00:00       1m   402.0   \n",
       "1        40922   i2109      DCE  2021-01-28 21:01:00       1m   204.0   \n",
       "2        40923   i2109      DCE  2021-01-28 21:02:00       1m   454.0   \n",
       "3        40924   i2109      DCE  2021-01-28 21:03:00       1m   346.0   \n",
       "4        40925   i2109      DCE  2021-01-28 21:04:00       1m   231.0   \n",
       "...        ...     ...      ...                  ...      ...     ...   \n",
       "221953  275307  IF2201    CFFEX  2021-12-30 15:24:00       1m     0.0   \n",
       "221954  275308  IH2201    CFFEX  2021-12-30 15:24:00       1m     0.0   \n",
       "221955  275309  IC2201    CFFEX  2021-12-30 15:26:00       1m     0.0   \n",
       "221956  275310  IF2201    CFFEX  2021-12-30 15:26:00       1m     0.0   \n",
       "221957  275311  IH2201    CFFEX  2021-12-30 15:26:00       1m     0.0   \n",
       "\n",
       "        open_interest  open_price  high_price  low_price  close_price  \n",
       "0            107487.0       909.0       912.5      907.5        911.5  \n",
       "1            107406.0       912.0       912.0      910.5        910.5  \n",
       "2            107210.0       910.0       911.0      906.5        907.0  \n",
       "3            107113.0       907.0       910.0      906.0        906.0  \n",
       "4            107043.0       905.5       908.5      905.0        907.5  \n",
       "...               ...         ...         ...        ...          ...  \n",
       "221953        80206.0      4940.0      4940.0     4940.0       4940.0  \n",
       "221954        52452.0      3277.0      3277.0     3277.0       3277.0  \n",
       "221955        94072.0      7342.8      7342.8     7342.8       7342.8  \n",
       "221956        80206.0      4940.0      4940.0     4940.0       4940.0  \n",
       "221957        52452.0      3277.0      3277.0     3277.0       3277.0  \n",
       "\n",
       "[221958 rows x 11 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1d767832",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
